package com.util;

public class Content {

	public static String shorten(String content){
		
		if (content.length()>170) {
			String string=content.substring(0,170);
			string+="......";
			content=string;
		}
		
		return content;
	}
	
	public static String shorten(String content,int l){
		
		if (content.length()>l) {
			String string=content.substring(0,l);
			string+="......";
			content=string;
		}
		
		return content;
	}
	
	public static String cal(String s){
		String length="";
		long size=Long.parseLong(s);
		
		if (size<1024) {
			length=size+"B";
		}else if (size<1024*1024) {
			length=size/1024+"KB";
		}else if (size<1024*1024*1024) {
			length=size/1024/1024+"MB";
		}else {
			length=size/1024/1024/1024+"GB";
		}
		
		return length;
	}
	
	public static String replace(String content){
		content=content.replaceAll(">","&gt;");
		content=content.replaceAll("<","&lt;");
		return content;
	}
	
	public static String replaceTo(String content){
		content=content.replaceAll("&gt;",">");
		content=content.replaceAll("&lt;","<");
		return content;
	}
	
}
